package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageCarDto;
import com.itsq.pojo.dto.PageCompanyDto;
import com.itsq.pojo.entity.Car;
import com.itsq.pojo.entity.Company;
import com.itsq.service.resources.CompanyService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-29
 */
@RestController
@RequestMapping("/company")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "单位信息模块")
public class CompanyController  extends BaseController {

    @Autowired
    private CompanyService companyService;

    @PostMapping("selCompanyPageFront")
    @ApiOperation(value = "单位信息模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Company>> selCompanyPageFront(@RequestBody PageCompanyDto pageCompanyDto){
        Page<Company> CompanyPage = companyService.selCompanyPageFront(pageCompanyDto);
        return Response.success(CompanyPage);
    }

    @PostMapping("selCompanyPageAfter")
    @ApiOperation(value = "管理员——单位信息模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Company>> selCompanyPageAfter(@RequestBody PageCompanyDto pageCompanyDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<Company> CompanyPage = companyService.selCompanyPageAfter(pageCompanyDto);
        return Response.success(CompanyPage);
    }

    @PostMapping("insert")
    @ApiOperation(value = "管理员——单位信息模块添加", notes = "", httpMethod = "POST")
    public Response<Integer> insert(@RequestBody Company company){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(companyService.insert(company));
    }

    @PostMapping("update")
    @ApiOperation(value = "管理员——单位信息模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Company company){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(companyService.update(company));
    }

    @PostMapping("selCompanyList")
    @ApiOperation(value = "单位信息模块list查询", notes = "", httpMethod = "POST")
    public Response<List<Company>> selCompanyList(){
        return Response.success(companyService.selCompanyList());
    }

    @PostMapping("selCompanyId")
    @ApiOperation(value = "单位信息模块id查询", notes = "", httpMethod = "POST")
    public Response<Company> selCompanyId(Integer id){
        return Response.success(companyService.selCompanyId(id));
    }

    @PostMapping("delete")
    @ApiOperation(value = "单位信息模块删除", notes = "", httpMethod = "POST")
    public Response<Integer> delete(Integer id){
        return Response.success(companyService.delete(id));
    }
}

